﻿using Microsoft.AspNetCore.Mvc;
using yunbo.Model.BIQI;
using yunbo.Repositorys.BIQIRepositorys;

namespace yunbo.Controllers.BIQIControllers
{
	[Route("api/[controller]")]
	[ApiController]
	public class QMS_ZJQXController : Controller
	{
		QMS_ZJQXRepository qMS_ZJQXRepository = new QMS_ZJQXRepository();


		/// <summary>
		/// 获取质检标准
		/// </summary>
		/// <param name="state"></param>
		/// <param name="str"></param>
		/// <returns></returns>
		[HttpGet("GetQMS_ZJQX")]
		public IActionResult GetQMS_ZJQX(int state, string? str)
		{
			List<QMS_ZJQX> zjqx = qMS_ZJQXRepository.GetQMS_ZJQX(state, str);
			return Ok(zjqx);
		}

		/// <summary>
		/// 改变状态
		/// </summary>
		/// <param name="id"></param>
		/// <param name="state"></param>
		/// <returns></returns>
		[HttpPut("StateChange")]
		public IActionResult StateChange(int id, int state)
		{
			bool res = qMS_ZJQXRepository.StateChange(id, state);
			return Ok(res);
		}


		/// <summary>
		/// 新增
		/// </summary>
		/// <param name="zjqx"></param>
		/// <returns></returns>
		[HttpPost("AddQMS_ZJQX")]
		public IActionResult AddQMS_ZJQX(QMS_ZJQX zjqx)
		{
			// 数据验证（可选）
			if (string.IsNullOrEmpty(zjqx.zjqx_name)
				|| zjqx.zjqx_fl <= 0
				|| string.IsNullOrEmpty(zjqx.zjqx_cpfl)
				)
			{
				return BadRequest("Invalid dictionary data."); // 如果数据无效，返回 400 Bad Request
			}

			bool res = qMS_ZJQXRepository.AddQMS_ZJQX(zjqx);
			return Ok(res);
		}


		/// <summary>
		/// 修改
		/// </summary>
		/// <param name="zjqx"></param>
		/// <returns></returns>
		[HttpPut("UpdateQMS_ZJQX")]
		public IActionResult UpdateQMS_ZJQX(QMS_ZJQX zjqx)
		{
			// 数据验证（可选）
			if (string.IsNullOrEmpty(zjqx.zjqx_name)
				|| zjqx.zjqx_fl <= 0
				|| string.IsNullOrEmpty(zjqx.zjqx_cpfl)
				|| zjqx.zjqx_id <= 0
				)
			{
				return BadRequest("Invalid dictionary data."); // 如果数据无效，返回 400 Bad Request
			}

			bool res = qMS_ZJQXRepository.UpdateQMS_ZJQX(zjqx);
			return Ok(res);
		}


		/// <summary>
		/// 删除
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpPut("DelQMS_ZJQX")]
		public IActionResult DelDW(int id)
		{
			bool res = qMS_ZJQXRepository.DelQMS_ZJQX(id);
			return Ok(res);
		}


		/// <summary>
		/// 批量删除
		/// </summary>
		/// <param name="ids"></param>
		/// <returns></returns>
		[HttpPut("DelQMS_ZJQXs")]
		public IActionResult DelDWs(int[] ids)
		{
			bool res = qMS_ZJQXRepository.DelQMS_ZJQXs(ids);
			return Ok(res);
		}
	}
}
